package mmc.objects;

import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;

import org.lwjgl.opengl.GL11;

import mmc.EngineObject;
import mmc.server.Player;
import mmc.server.Server;


public class Portal extends EngineObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private float despawnTime = 60;
	private transient float start;
	public transient Player player;

	public Portal(float x, float y, float z) {
		super(x, y, z);
		start = 0;
	
		// TODO Auto-generated constructor stub
	}

	@Override
	public void render(EngineObject observer) {
		// TODO Auto-generated method stub
		glPushMatrix();
		GL11.glTranslatef(x, y+0.001f, z);  
		radialGradientCircle(new float[]{1,0,1,1}, new float[]{0, 1 ,0,1}, 15, 0.5f);
		glPopMatrix(); 
	}
	
	
	@Override
	public void update(Server server, float dt){		
		start += dt;	
		
		if(start > despawnTime){
			server.getScene().removeObject(this);
			dirty = true;
		}
		
		if(this.inRange(player, 1))
		{
			player.heal(1);
			this.kill();
			//System.out.println("ASDAS");
			
			/*
			EngineObject spawnPoint =new Mark(player.x + 10, player.y + 10, player.z +10); 
			player.moveTo(spawnPoint);			
			player.vx = player.vy = player.vz = 0;			
			player.dirty = true;
			
			Respawn r = new Respawn(server.getScene(),spawnPoint);
			player.addKnownChunks(r.ca);
			player.getClient().post(r);*/
		}
	}

	public void resetPos(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
		this.start = 0; 
	}

	@Override
	public void update(float dt) {
		// TODO Auto-generated method stub
		
	}

}
